home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / shadow-3.1.4 / hushed.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-26  |  1.6 KB  |  77 lines

  1. /*
  2.  * Copyright 1991, John F. Haugh II and Chip Rosenthal
  3.  * All rights reserved.
  4.  *
  5.  * Permission is granted to copy and create derivative works for any
  6.  * non-commercial purpose, provided this copyright notice is preserved
  7.  * in all copies of source code, or included in human readable form
  8.  * and conspicuously displayed on all copies of object code or
  9.  * distribution media.
  10.  */
  11.  
  12. #ifndef lint
  13. static    char    sccsid[] = "@(#)hushed.c    3.1    07:47:53    9/17/91";
  14. #endif
  15.  
  16. #include <stdio.h>
  17. #ifndef BSD
  18. # include <string.h>
  19. #else
  20. # include <strings.h>
  21. #endif
  22. #include "config.h"
  23. #include "pwd.h"
  24.  
  25. extern char *getdef_str();
  26.  
  27. /*
  28.  * hushed - determine if a user receives login messages
  29.  *
  30.  * Look in the hushed-logins file (or user's home directory) to see
  31.  * if the user is to receive the login-time messages.
  32.  */
  33.  
  34. int
  35. hushed(pw)
  36. struct passwd *pw;
  37. {
  38.     char *hushfile;
  39.     char buf[BUFSIZ];
  40.     int found;
  41.     FILE *fp;
  42.  
  43.     /*
  44.      * Get the name of the file to use.  If this option is not
  45.      * defined, default to a noisy login.
  46.      */
  47.  
  48.     if ( (hushfile=getdef_str("HUSHLOGIN_FILE")) == NULL )
  49.         return 0;
  50.  
  51.     /*
  52.      * If this is not a fully rooted path then see if the
  53.      * file exists in the user's home directory.
  54.      */
  55.  
  56.     if (hushfile[0] != '/') {
  57.         strcat(strcat(strcpy(buf, pw->pw_dir), "/"), hushfile);
  58.         return (access(buf, 0) == 0);
  59.     }
  60.  
  61.     /*
  62.      * If this is a fully rooted path then go through the file
  63.      * and see if this user is in there.
  64.      */
  65.  
  66.     if ((fp = fopen(hushfile, "r")) == NULL)
  67.         return 0;
  68.  
  69.     for (found = 0;! found && fgets (buf, sizeof buf, fp);) {
  70.         buf[strlen (buf) - 1] = '\0';
  71.         found = ! strcmp (buf,
  72.             buf[0] == '/' ? pw->pw_shell:pw->pw_name);
  73.     }
  74.     (void) fclose(fp);
  75.     return found;
  76. }
  77.